home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Views / Arrangements / ArrangementBase.cp < prev    next >
Text File  |  1997-06-28  |  2KB  |  119 lines

  1. // ArrangementBase.cp
  2.  
  3. #ifndef ArrangementBase_h
  4. #include "ArrangementBase.h"
  5. #endif
  6. #ifndef ArrangedPane_h
  7. #include "ArrangedPane.h"
  8. #endif
  9. #ifndef MinMax_h
  10. #include "MinMax.h"
  11. #endif
  12. #ifndef ViewMap_h
  13. #include "ViewMap.h"
  14. #endif
  15.  
  16. ArrangementBase::ArrangementBase( ArrangedPane *thePanes,
  17.                                              uint32 thePaneCount )
  18.   : panes( thePanes ),
  19.      paneCount( thePaneCount )
  20.   {
  21.     Assert( thePanes != 0 );
  22.   }
  23.  
  24. void ArrangementBase::SetParents()
  25.   {
  26.     for ( uint32 i = 0; i < paneCount; i++ )
  27.         panes[i].parent = this;
  28.   }
  29.  
  30. void ArrangementBase::Draw( const ViewMap& toDraw ) const
  31.   {
  32.     ViewMap paneMap( toDraw );
  33.     
  34.     for ( uint32 i = 0; i < paneCount; i++ )
  35.       {
  36.         const Pane& pane( panes[i] );
  37.         
  38.         paneMap.Set( toDraw, pane.Bounds() );
  39.         if ( !paneMap.Visible() )
  40.             continue;
  41.         
  42.         pane->Draw( paneMap );
  43.       }
  44.   }
  45.  
  46. TangibleView *ArrangementBase::Touch( PointObject p )
  47.   {
  48.     for ( uint32 i = 0; i < paneCount; i++ )
  49.       {
  50.         const Pane& pane( panes[i] );
  51.         
  52.         if ( pane.Bounds().Contains( p ) )
  53.             return pane->Touch( p );
  54.       }
  55.     
  56.     return 0;
  57.   }
  58.  
  59. void ArrangementBase::GainMapping()
  60.   {
  61.     Arrange( Owner().Bounds() );
  62.  
  63.     for ( uint32 i = 0; i < paneCount; i++ )
  64.         panes[i].MapTo( Owner().Window() );
  65.   }
  66.  
  67. void ArrangementBase::LoseMapping()
  68.   {
  69.     for ( uint32 i = 0; i < paneCount; i++ )
  70.         panes[i].Unmap();
  71.   }
  72.  
  73. void ArrangementBase::ChangeBounds( Rectangle )
  74.   {
  75.     if ( Mapped() )
  76.         Arrange( Owner().Bounds() );
  77.   }
  78.  
  79. uint16 ArrangementBase::Minimum( uint16 (Sizeable::*dimension)() ) const
  80.   {
  81.     uint16 min = maxuint16;
  82.     
  83.     for ( uint32 i = 0; i < paneCount; i++ )
  84.         if ( !panes[i].IsEmpty() )
  85.             min = Min( min, ( (*panes[i]).*dimension)() );
  86.     
  87.     return min;
  88.   }
  89.  
  90. uint16 ArrangementBase::Maximum( uint16 (Sizeable::*dimension)() ) const
  91.   {
  92.     uint16 max = 0;
  93.     
  94.     for ( uint32 i = 0; i < paneCount; i++ )
  95.         if ( !panes[i].IsEmpty() )
  96.             max = Max( max, ((*panes[i]).*dimension)() );
  97.     
  98.     return max;
  99.   }
  100.  
  101. uint16 ArrangementBase::Total( uint16 (Sizeable::*dimension)() ) const
  102.   {
  103.     uint16 total = 0;
  104.     for ( uint32 i = 0; i < paneCount; i++ )
  105.       {
  106.         if ( panes[i].IsEmpty() )
  107.             continue;
  108.         
  109.         uint16 paneSize = ((*panes[i]).*dimension)();
  110.         
  111.         if ( CanAdd( total, paneSize ) )
  112.             total += paneSize;
  113.          else
  114.             return maxuint16;
  115.       }
  116.     
  117.     return total;
  118.   }
  119.